/*   time:2019-06-13 20:39:48*/
var n = getApp(),
    t = n.requirejs("core");
n.requirejs("jquery"), n.requirejs("foxui"), Page({
    onPullDownRefresh: function() {
        var e = this;
        t.get("groups", {}, function(n) {
            var l = {}
            for(let i=0;i<n.recgoods.length;i++){
                for(let x=0;x<n.category.length;x++){
                    if(n.category[x].id==n.recgoods[i].category){
                        if(!l[n.category[x].name]){
                            l[n.category[x].name] = new Array()
                        }
                        l[n.category[x].name].push(n.recgoods[i])
                    }
                }
                //n.recgoods[i].lastime = a.dateLess(n.recgoods[i].startime,n.recgoods[i].endtime)
            }
            console.log(l)
            0 == n.error && (e.setData({
                res: l,
                list: n
            }), wx.stopPullDownRefresh())
        })
    },
    data: {
        swiperheight: 0,
    },
    onLoad: function(e) {
        var a = this;
        n.getCache("isIpx") ? a.setData({
            isIpx: !0,
            iphonexnavbar: "fui-iphonex-navbar"
        }) : a.setData({
            isIpx: !1,
            iphonexnavbar: ""
        }), t.get("groups", {}, function(n) {
            var l = {}
            for(let i=0;i<n.recgoods.length;i++){
                for(let x=0;x<n.category.length;x++){
                    if(n.category[x].id==n.recgoods[i].category){
                        if(!l[n.category[x].name]){
                            l[n.category[x].name] = new Array()
                        }
                        l[n.category[x].name].push(n.recgoods[i])
                    }
                }
                //n.recgoods[i].lastime = a.dateLess(n.recgoods[i].startime,n.recgoods[i].endtime)
            }
            console.log(l)
            a.setData({
                res: l,
                list: n
            })
        })
    },
    dateLess(fromDate, addtime){
        var date = new Date();
        //var date2 = new Date();
        var a=Date.parse(new Date(fromDate));//把时间转换成毫秒
        a=a+(1000*60*60*addtime);//增加24小时。
        var date2=new Date(a);//得到新的重新格式化时间。
        var s1 = date.getTime(),s2 = date2.getTime();
        var total = (s2 - s1)/1000;
        var day = parseInt(total / (24*60*60));//计算整数天数
        var afterDay = total - day*24*60*60;//取得算出天数后剩余的秒数
        var hour = parseInt(afterDay/(60*60));//计算整数小时数
        var afterHour = total - day*24*60*60 - hour*60*60;//取得算出小时数后剩余的秒数
        var min = parseInt(afterHour/60);//计算整数分
        var afterMin = parseInt(total - day*24*60*60 - hour*60*60 - min*60);//取得算出分后剩余的秒数
        if(day<0||hour<0||min<0){
            return 0;
        }
        if(day === 0){
            if(hour === 0){
                return min+"分钟";
            }else{
                return hour+"小时";
            }
        }else{
            return day+"天"+hour+"小时";
        }

},

    advheight: function(n) {
        var t = n.detail.width / n.detail.height;
        this.setData({
            advheight: 750 / t
        })
    },
    navigate: function(n) {
        var e = t.pdata(n).link;
        wx.navigateTo({
            url: e,
            fail: function() {
                wx.switchTab({
                    url: e
                })
            }
        })
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onReachBottom: function() {
        this.onPullDownRefresh()
    },
    onShareAppMessage: function() {},

    imageLoad: function (e) {
        var windowWidth = wx.getSystemInfoSync().windowWidth
        var windowHeight = wx.getSystemInfoSync().windowHeight
        var imgwidth = e.detail.width
        var imgheight = e.detail.height
        this.setData({
            swiperheight:(imgheight * (windowWidth/imgwidth)).toFixed(3)
        })
    },

});